package com.product.service;

import com.product.dao.ProductDao;
import com.product.entity.Product;
import com.product.util.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    private ProductDao productDao;

    public CommonResponse list(){
        List<Product> products = productDao.selectProduct();
        return new CommonResponse<List>(200,"ok",products);
    }

    public CommonResponse search(String target) {
        System.out.println(target);
        List<Product> products = productDao.selectProductByName(target);
        System.out.println(products.size());
        if (!products.isEmpty())
            return new CommonResponse<List>(200,"ok",products);
        return new CommonResponse(500,"empty result");
    }
}
